package ch.fhnw.qualiscan.application.elements;

import ch.fhnw.qualiscan.Config;
import ch.fhnw.qualiscan.application.modals.AddParticipantToSurvey;
import ch.fhnw.qualiscan.application.modals.EditFinalEvaluation;
import ch.fhnw.qualiscan.application.modals.Export;
import ch.fhnw.qualiscan.application.modals.ShowParticipants;
import ch.fhnw.qualiscan.core.db.pojos.SurveyUserRole;
import ch.fhnw.qualiscan.core.helpers.SessionHelper;
import ch.fhnw.qualiscan.core.helpers.TextHelper;
import ch.fhnw.qualiscan.core.libraries.ModalLib;

import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.BaseTheme;

import eu.livotov.tpt.i18n.TM;

@SuppressWarnings("serial")
public class EvaluationOptionsBox extends VerticalLayout {
	
	public SurveyUserRole sur;
	
	public TextHelper textHelper;
	public SessionHelper sessionHelper;
	public ModalLib modalLib;
	
	public EvaluationOptionsBox(SurveyUserRole sur) {
		
		setSpacing(true);
		textHelper = new TextHelper();
		sessionHelper = new SessionHelper();
		modalLib = new ModalLib();
		
		this.sur = sur;
		buildComponent();
	}

	public void buildComponent() {
		
		setSpacing(true);
		setMargin(false, true, false, true);
		setStyleName("options");
		
		// title
		addComponent(textHelper.bigSpan(TM.get("evaluation.options")));
		
		if(sur.getRole().getId() == Config.COORDINATOR_ID) {
			Button finalReport = new Button(TM.get("evaluation.final"));
			finalReport.setStyleName(BaseTheme.BUTTON_LINK);
			finalReport.addListener(new Button.ClickListener() {
				public void buttonClick(ClickEvent event) {
					modalLib.openModal(new EditFinalEvaluation(sur));
				}
			});
			finalReport.setIcon(Config.ICON_FINALREPORT);
			addComponent(finalReport);
			
			Button participants = new Button(TM.get("evaluation.seeparticipants"));
			participants.setStyleName(BaseTheme.BUTTON_LINK);
			participants.addListener(new Button.ClickListener() {
				public void buttonClick(ClickEvent event) {
					modalLib.openModal(new ShowParticipants(sur));
				}
			});
			participants.setIcon(Config.ICON_USER);
			addComponent(participants);
			
			Button inviteExpert = new Button(TM.get("evaluation.invite"));
			inviteExpert.setStyleName(BaseTheme.BUTTON_LINK);
			inviteExpert.addListener(new Button.ClickListener() {
				public void buttonClick(ClickEvent event) {
					modalLib.openModal(new AddParticipantToSurvey(sur.getSurvey()));
				}
			});
			inviteExpert.setIcon(Config.ICON_ADDUSER);
			addComponent(inviteExpert);
		}
		
		Button export = new Button(TM.get("evaluation.export"));
		export.setStyleName(BaseTheme.BUTTON_LINK);
		export.addListener(new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				modalLib.openModal(new Export(sur));
			}
		});
		export.setIcon(Config.ICON_EXPORT);
		addComponent(export);
	}
	
}
